# from redis import Redis
#
# conn = Redis(host='localhost', port=6379, password=None)
#
# conn.set('name', 'lzj')
# res = conn.get('name')
# print(res)


import redis
from redis_pool import POOL

conn = redis.Redis(connection_pool=POOL)
# print(conn.get('name'))

# set 设置指定 key.txt 值

# conn.set('age', 18)
# conn.set('name', '刘志金')
# conn.set('gender', 'man', ex=3)


# print(str(conn.get('name'),encoding='utf-8'))


# conn.setnx('name', 'lxx')

# conn.setnx('gender', 'male')

# conn.setex('xx', 5, 'yy')  # 设置key值xx，value值yy，5秒钟过期
# conn.psetex('xx', 5000, 'yy')

# conn.mset({'name':'lxx','age':19})


# print(conn.mget(['name','age']))

# print(conn.mget('name','age'))

# res = conn.getset('name', 'lyy')
# print(res)
# res = conn.getrange('name',0,0)
# res = conn.getrange('name', 0, 2)
# print(res)
# conn.setrange('name', 2, 'zzz')

# print(conn.strlen('name'))
# conn.incr('age')
# conn.decr('age')

# conn.append('name', 'nb')
# conn.append('this', 'is key.txt')

# conn.hset('hast_test', 'name', 'lqz')
# conn.hset('hast_test', 'age', '18')

# print(conn.hget('hast_test', 'name'))
# print(conn.hget('hast_test', 'age'))

# print(conn.hmget('hast_test', ['name', 'age']))
# print(conn.hgetall('hast_test'))
# print(conn.hlen('hast_test'))

# print(conn.hkeys('hast_test'))


# print(conn.hvals('hast_test'))

# print(conn.hexists('hast_test', 'name'))
# print(conn.hexists('hast_test', 'ha'))


# conn.hincrby('hast_test', 'age', amount=10)

# for i in range(1000):
#     conn.hset('test', '%s-%s' % ('key.txt', i),i)

# res = conn.hscan('test', cursor=0, count=100)
# print(res)
# print(len(res[1]))
#
# res = conn.hscan('test',cursor=res[0],count=100)
# print(res)
# print(len(res[1]))

# for item in conn.hscan_iter('test',count=10):
#     print(item)
# conn.lpush('list_test', 'egon')
# conn.lpush('list_test', 'lqz')

# conn.rpush('list_test', 'szw', 'ylf')

conn.lpushx('list_test', 'egon')
conn.close()
